using COC.Debug;
using UnityEngine;
using System.Collections;
using System.IO;

namespace COC.Tool{
    public class FileTools 
{
	// get a log instance
	//private static ILog logger = LogManager.GetLogger(typeof(FileTools));
	/// <summary>
	/// Creates the directorys through file separator "/"+path:d1/d2/d3
	/// </summary>
	/// <returns><c>true</c>, if directorys was created, <c>false</c> otherwise.</returns>
	/// <param name="paths">Paths.</param>
	/// 
	public static string CreateDirectorys(string Paths,string Parent){
		string _paths="";
		if(Paths.Length>0){
		string segement="";
		string subPath="";
		_paths=Parent+"/"+(Paths.LastIndexOf("/")==Paths.Length-1?Paths:Paths+"/");
		segement=_paths.Substring(Parent.Length+1,Paths.IndexOf("/"));
        DebugTool.Log(_paths + " ;" + "segement= " + (_paths.IndexOf(segement, Parent.Length + 1) + 1) + "length=" + (_paths.Length - segement.Length - Parent.Length));
		if(CreateDirectory(segement,Parent)){
            DebugTool.Log("subPath=" + _paths);
			subPath=_paths.Substring((_paths.IndexOf(segement,Parent.Length+1)+1+segement.Length));
			return CreateDirectorys(subPath,Parent+"/"+segement);
			}
			return _paths;
		}
		if(Parent.Length>Application.dataPath.Length){
			return Parent;
		}
		return _paths;
	}
	public static bool CreateDirectory(string path,string Parent){
		if(Parent==null|| Parent.Equals(""))
			Parent=Application.dataPath;
		else
		if(path.Length>0){
			if(!Directory.Exists(Parent+"/"+path)){
				try {
					Directory.CreateDirectory(Parent+"/"+path);
				} catch (System.Exception ex) {
                    DebugTool.LogError("Cannot create directory,because:" + ex.Message);
					return false;
				}
				return true;
			}
		}
		return true;
	}

	public static bool CreateFileOrDirectory(string Name,string Parent,bool isFile){

		return false;
	}
}

}